package com.cqndt.visual.controller;

import com.cqndt.visual.dao.entity.TabUser;
import com.cqndt.visual.service.BusinessService;
import com.cqndt.visual.sevcie.TestService;
import com.cqndt.visual.udp.client.UdpClient;
import com.cqndt.visual.util.FileViewUtil;
import com.cqndt.visual.util.Result;
import com.cqndt.visual.vo.CaseVo;
import com.cqndt.visual.vo.FlightDataVo;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * Created By marc
 * Date: 2021/5/12  14:10
 * Description:
 */
@RestController
@RequestMapping("/instruct")
public class InstructController {

    private static final Logger logger = LoggerFactory.getLogger(InstructController.class);

    @Autowired
    private BusinessService businessService;

    @Autowired
    TestService testService;

    @Autowired
    UdpClient udpClient;

    @PostMapping("/test")
    public String test() {
        logger.info("test: {}", 1111);
        FlightDataVo vo = new FlightDataVo();
        vo.setUavSn("1111111");
        vo.setAiPeopleNum("22");
        vo.setAirSpeed("23");
        vo.setAngle("12.0334");
        udpClient.sendMessage(vo);
        return "hello world";
    }

    @PostMapping("/test1")
    @ApiOperation(value = "测试", notes = "测试")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "String", name = "dataPath", value = "路径", defaultValue = "0", required = true, paramType = "query"),
            @ApiImplicitParam(dataType = "String", name = "suffixName", value = "后缀名", defaultValue = "0", required = true, paramType = "query")
    })

    public TabUser test1(Integer id) {
        return testService.test(id);
    }

    /**
     * sc create uvas binPath= D:/startup.bat start= auto
     * 获取飞行参数

     * @return
     */
    @GetMapping("/fightData")
    public Result fightData() {
        businessService.fightDetailData();
//        Cache cache = cacheManager.getCache("uavSn");
//        FlightDataVo vo = cache.get(uavSn,FlightDataVo.class);
        return new Result().success();
    }

    @GetMapping("/getByIo/{code}")
    public void getByIo(@PathVariable(required = true, value = "code") String code,HttpServletResponse respons) {
        String attachmentUrl = "D:\\POWERGIS\\uav\\img\\hangxian.jpg";
        if("1".equals(code)){
            attachmentUrl = "D:\\POWERGIS\\uav\\radio\\hangxian.mp4";
        }
        FileViewUtil.readByIo(attachmentUrl,respons);
    }


    @PostMapping("/publishTask")
    public Result publishTask(@RequestBody CaseVo caseVo) {
        System.out.println(caseVo.toString());
        return businessService.publishTask(caseVo);
    }



    @GetMapping("/getWarn")
    public void getWarn(String uavSn) {
        businessService.sendMessage(uavSn);
    }
}
